package com.ybkj.daijia.server.scheduler;

import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.server.Config;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author FZH
 */
@Component
public class TrashClear {

    private static final Logger logger = LoggerFactory.getLogger(TrashClear.class);

    @Autowired
    private SettingUtils settingUtils;

    @Transactional(rollbackFor = Exception.class)
    public void clear() {

        logger.debug("开始导出历史文件清除任务...");

        String webapp = Config.getWebapp();

        File dir = new File(String.format("%s/download/excel/", webapp));
        if (dir.exists()) {
            try {
                FileUtils.deleteDirectory(dir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        logger.debug("结束导出历史文件清除任务...");

        logger.debug("开始二维码清除任务...");

        dir = new File(String.format("%s/qrcode/member/", webapp));
        if (dir.exists()) {
            try {
                FileUtils.deleteDirectory(dir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        dir = new File(String.format("%s/qrcode/driver/", webapp));
        if (dir.exists()) {
            try {
                FileUtils.deleteDirectory(dir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        logger.debug("结束二维码清除任务...");

    }

}
